package com.example.sms.response;

import java.io.Serializable;


public class ResponseModel<T> implements Serializable {

    private String status;
    private String msg;
    private T data;
    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
    public void setMsg(String msg) {
        this.msg = msg;
    }

    public ResponseModel(){}
    public ResponseModel(String status){
        this.status=status;
    }
    public ResponseModel(String status, String msg){
        this.status=status;
        this.msg=msg;
    }
    public ResponseModel(String status, String msg,T data){
        this.status=status;
        this.msg=msg;
        this.data=data;
    }

    /**
     * 请求响应成功的结果封装
     *
     * @param data 请求响应的数据
     * @param <T>  数据泛型声明
     * @return 响应封装结果
     */
    public static <T> ResponseModel<T> success(T data) {
        return new ResponseModel<>(ResponseCode.SUCCESS, "成功", data);
    }

    /**
     * 请求响应失败的结果封装
     *
     * @param msg 错误提示信息
     * @return 响应封装结果
     */
    public static ResponseModel<Object> failure(String msg) {
        return new ResponseModel<>(ResponseCode.BUSINESS_ERROR, msg, new String[0]);
    }
}
